<template>
    <Transition>
        <div class="contain" v-if="flag">
            <div class="card">
                <div class="header flex">
                    <div class="goHome flex">
                        <p class="title">{{ title }}</p>
                    </div>
                    <div class="flex">
                        <button class="submit" @click="addHandle"
                            v-loading.fullscreen.lock="fullscreenLoading">提交</button>
                        <el-icon size="22" style="margin-right: 37px; cursor: pointer;" @click="clear">
                            <Close />
                        </el-icon>
                    </div>
                </div>
                <div class="main">
                    <div class="inputBox">
                        <p class="inputName">中心主任<span>*</span></p>
                        <el-select v-model="addBaseDepartmentForm.leader2" placeholder="请选择中心主任" class="select"
                            clearable filterable>
                            <el-option v-for="item in list" :key="item.teacherNumber" :label="item.name"
                                :value="item.teacherNumber" />
                        </el-select>
                    </div>
                    <div class="inputBox">
                        <p class="inputName">主管校长<span>*</span></p>
                        <el-select v-model="addBaseDepartmentForm.leader3" placeholder="请选择主管校长" class="select"
                            clearable filterable>
                            <el-option v-for="item in list" :key="item.teacherNumber" :label="item.name"
                                :value="item.teacherNumber" />
                        </el-select>
                    </div>
                    <div class="inputBox">
                        <p class="inputName">校区校长<span>*</span></p>
                        <el-select v-model="addBaseDepartmentForm.leader4" placeholder="请选择校区校长" class="select"
                            clearable filterable>
                            <el-option v-for="item in list" :key="item.teacherNumber" :label="item.name"
                                :value="item.teacherNumber" />
                        </el-select>
                    </div>

                </div>
            </div>
        </div>
    </Transition>
</template>

<script>
import { httpService } from "@/utils/httpService";
import Icon from '@/components/Icon.vue';
import { ArrowLeft, Close } from "@element-plus/icons-vue";
import { ElMessage, ElForm, ElLoading } from "element-plus";

export default {
    name: "leftMenu",
    components: { Icon, ArrowLeft, ElMessage, ElForm, ElLoading, Close },
    data() {
        return {
            flag: false,
            form: {
                parentId: "",
                name: "",
            },
            title: "",
            user: {},
            list: [],
            fullscreenLoading: false,
            addBaseDepartmentForm: {
                leader4: "",
                leader3: "",
                leader2: "",
                leader1: "",
                parentId: "",
                name: "",
                orderNum: "",
                type: "",
                campus: "",
            },
        };
    },
    computed: {},
    mounted() {

    },
    methods: {
        getBaseDepartmentById(id) {
            httpService("/javaApi/baseDepartment/queryById", { id: id }, "get").then(
                (data) => {
                    this.addBaseDepartmentForm = data;
                    console.log(this.addBaseDepartmentForm);
                }
            );
        },
        getBaseTeacherListApp() {
            httpService(
                "/javaApi/baseTeacher/list/1/10000",
                { noCampus: 1, }, "get"
            ).then((data) => {
                this.list = data.list;
            });
        },


        addHandle() {
            if (!this.addBaseDepartmentForm.leader2) {
                ElMessage.error("请选择中心主任")
            } else if (!this.addBaseDepartmentForm.leader3) {
                ElMessage.error("请选择主管校长")
            } else if (!this.addBaseDepartmentForm.leader4) {
                ElMessage.error("请选择校区校长")
            } else {
                this.fullscreenLoading = true
                let params = new FormData(); //创建一个form对象,必须是form对象否则后端接受不到数据
                params.append("name", this.addBaseDepartmentForm.name);
                params.append("orderNum", this.addBaseDepartmentForm.orderNum);
                params.append("type", this.addBaseDepartmentForm.type);
                params.append("leader1", this.addBaseDepartmentForm.leader1);
                params.append("leader2", this.addBaseDepartmentForm.leader2);
                params.append("leader3", this.addBaseDepartmentForm.leader3);
                params.append("leader4", this.addBaseDepartmentForm.leader4);

                if (this.addBaseDepartmentForm.id) {
                    params.append("id", this.addBaseDepartmentForm.id);
                    httpService("/javaApi/baseDepartment/edit", params, "post").then(
                        (data) => {
                            if (data.code == 200) {
                                ElMessage.success(data.object);
                                this.clear();
                                this.fullscreenLoading = false
                                //刷新父组件的数据
                                this.$parent.getList();
                            } else {
                                ElMessage.error(data.message);
                            }
                        }
                    );
                } else {
                    httpService("/javaApi/baseDepartment/add", params, "post").then(
                        (data) => {
                            if (data.code == 200) {
                                ElMessage.success(data.object);
                                this.clear();
                                this.fullscreenLoading = false
                                //刷新父组件的数据
                                this.$parent.getList();
                            } else {
                                ElMessage.error(data.message);
                            }
                        }
                    );
                }
            }
        },

        clear() {
            this.flag = false
            this.form.id = ""
            this.form.name = ""
            this.form.parentId = ""
        },



    },
}
</script>

<style scoped>
* {
    margin: 0;
    padding: 0;
}

.flex {
    display: flex;
    align-items: center;
}

.contain {
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.35);
    position: fixed;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    z-index: 99;
    display: flex;
    align-items: flex-start;
    justify-content: center;
}

.card {
    width: 60%;
    background-color: #fff;
    border-radius: 13px;
    padding-bottom: 50px;
    margin-top: 150px;
}

.header {
    justify-content: space-between;
    height: 65px;
    border-bottom: 1px solid #D6DBE2;
}

.header .title {
    color: #000000;
    font-size: 18px;
    font-weight: bold;
    margin-left: 32px;
}

.submit {
    width: 77px;
    height: 38px;
    background-color: #6F72FF;
    border-radius: 10px;
    border: none;
    margin-right: 32px;
    color: #fff;
    font-size: 15px;
}

.main {
    width: 50vw;
    padding: 23px 52px 0 52px;
    margin: 10px auto 0;
    display: flex;
    justify-content: space-between;
    flex-direction: column;
    flex-wrap: wrap;
    align-content: flex-start;
    overflow-y: auto;
}

.inputBox {
    /* width: calc((100% - 100px) / 3); */
    width: 100%;
    margin-bottom: 15px;
}

.inputName {
    color: #5B686D;
    font-size: 15px;
    margin-bottom: 5px;
}

.myInput {
    width: calc(100% - 19px);
    height: 42px;
    border-radius: 10px;
    border: 1px solid #D6DBE2;
    outline: none;
    font-size: 15px;
    color: #000;
    padding-left: 19px;
}

.myInput::placeholder {
    color: #A9B6BB;
}

.myText {
    width: calc(100% - 36px);
    height: 150px;
    border-radius: 10px;
    border: 1px solid #D6DBE2;
    resize: none;
    outline: none;
    padding: 18px;
    font-size: 15px;
    color: #000;
}

.myText::placeholder {
    color: #A9B6BB;
}


input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* 对于Firefox */
input[type="number"] {
    -moz-appearance: textfield;
}

.select ::v-deep .el-tooltip__trigger {
    width: 100%;
    height: 44px;
    border-radius: 10px;
    cursor: pointer;
}


.el-select-dropdown__item {
    padding-left: 15px;
}

::v-deep .el-select {
    --el-color-primary: #D6DBE2;
}



.v-enter-active,
.v-leave-active {
    transition: opacity 0.5s ease;
}

.v-enter-from,
.v-leave-to {
    opacity: 0;
}

.inputName span {
    color: #F00;
}
</style>